//
//  HWRechargeButton.m
//  嗨文
//
//  Created by 响当当 on 2019/1/14.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWRechargeButton.h"

@interface HWRechargeButton()
@property (nonatomic, strong)UIImageView *hotImageView;//hot图标
@property (nonatomic, strong)UILabel *moneyLabel;//金额
@property (nonatomic, strong)UILabel *coinMoneyLabel;//书币
@property (nonatomic, strong)UIImageView *giveImageView;//赠送
@property (nonatomic, strong)UILabel *bookLabel;//书券
@property (nonatomic, strong)UIImageView *firstRechargeImageView;//赠送

@end

@implementation HWRechargeButton

- (UIImageView *)hotImageView
{
    if (!_hotImageView)
    {
        _hotImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30*kUIScaleBasePlus,12*kUIScaleBasePlus,20*kUIScaleBasePlus,23*kUIScaleBasePlus)];
        _hotImageView.image = [UIImage imageNamed:@"hot"];
    }
    return _hotImageView;
}

- (UILabel *)moneyLabel
{
    if (!_moneyLabel)
    {
        _moneyLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,15*kUIScaleBasePlus,self.frame.size.width,20*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentCenter
                                             textClor:LCHexColor(0x333333)
                                             textFont:18*kUIScaleBasePlus];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:24*kUIScaleBasePlus];
    }
    return _moneyLabel;
}

- (UILabel *)coinMoneyLabel
{
    if (!_coinMoneyLabel)
    {
        _coinMoneyLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,CGRectGetMaxY(self.moneyLabel.frame)+10*kUIScaleBasePlus,self.frame.size.width,12*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentCenter
                                             textClor:LCHexColor(0xF9AF34)
                                             textFont:12*kUIScaleBasePlus];
    }
    return _coinMoneyLabel;
}

- (UIImageView *)giveImageView
{
    if (!_giveImageView)
    {
        _giveImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,62*kUIScaleBasePlus,15*kUIScaleBasePlus,15*kUIScaleBasePlus)];
        _giveImageView.image = [UIImage imageNamed:@"present_ticket"];
    }
    return _giveImageView;
}

- (UILabel *)bookLabel
{
    if (!_bookLabel)
    {
        _bookLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,CGRectGetMaxY(self.coinMoneyLabel.frame)+11*kUIScaleBasePlus,0,12*kUIScaleBasePlus)
                                        textAligment:NSTextAlignmentCenter
                                            textClor:LCHexColor(0x333333)
                                            textFont:12*kUIScaleBasePlus];
    }
    return _bookLabel;
}

- (UIImageView *)firstRechargeImageView
{
    if (!_firstRechargeImageView)
    {
        _firstRechargeImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,53*kUIScaleBasePlus,25*kUIScaleBasePlus,16*kUIScaleBasePlus)];
        _firstRechargeImageView.image = [UIImage imageNamed:@"first_charge"];
    }
    return _firstRechargeImageView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 4;
        self.layer.borderColor = LCHexColor(0xFEAD28).CGColor;
        self.layer.borderWidth = 1;
        
        [self addSubview:self.hotImageView];
        [self addSubview:self.moneyLabel];
        [self addSubview:self.coinMoneyLabel];
        [self addSubview:self.giveImageView];
        [self addSubview:self.bookLabel];
        [self addSubview:self.firstRechargeImageView];
    }
    return self;
}

#pragma mark - 获取充值数据
- (void)getRechargeDate:(NSDictionary *)dic andIsFirstRecharge:(NSString *)isFirstRecharge ishide:(NSString *)hide
{
    NSString *moneyStr = @"";
    if ([hide isEqualToString:@"1"])
    {
        moneyStr = [NSString stringWithFormat:@"%@",dic[@"cashAmount"]];
    }
    else
    {
        moneyStr = [NSString stringWithFormat:@"¥%@",dic[@"cashAmount"]];
    }
    
    if ([hide isEqualToString:@"1"])
    {
        if ([moneyStr isEqualToString:@"10"])
        {
            moneyStr = [NSString stringWithFormat:@"¥%ld",moneyStr.integerValue+2];
        }
        else if([moneyStr isEqualToString:@"20"])
        {
            moneyStr = [NSString stringWithFormat:@"¥%ld",moneyStr.integerValue+5];
        }
        else if([moneyStr isEqualToString:@"30"])
        {
            moneyStr = [NSString stringWithFormat:@"¥%ld",moneyStr.integerValue];
        }
        else if([moneyStr isEqualToString:@"50"])
        {
            moneyStr = [NSString stringWithFormat:@"¥%ld",moneyStr.integerValue];
        }
        else if([moneyStr isEqualToString:@"100"])
        {
            moneyStr = [NSString stringWithFormat:@"¥%ld",moneyStr.integerValue+8];
        }
        else if([moneyStr isEqualToString:@"200"])
        {
            moneyStr = [NSString stringWithFormat:@"¥%ld",moneyStr.integerValue+8];
        }
    }
    
   
    
    self.moneyLabel.attributedText = [moneyStr addAttriButedString:moneyStr
                                                             Color:LCHexColor(0x333333)
                                                              Font:[UIFont boldSystemFontOfSize:16*kUIScaleBasePlus]
                                                              rang:NSMakeRange(0,1)];
    [self.moneyLabel sizeToFit];
    
    
    self.coinMoneyLabel.text = [NSString stringWithFormat:@"%@书币",dic[@"goodsNum"]];
    self.moneyLabel.centerX = self.coinMoneyLabel.centerX;
    
    if ([dic[@"isHot"] isEqual:@0])
    {
        self.hotImageView.hidden = YES;
    }
    else
    {
        self.hotImageView.centerX = self.moneyLabel.centerX-12*kUIScaleBasePlus-25*kUIScaleBasePlus;
        self.hotImageView.hidden = NO;
    }
    
    self.bookLabel.text = [NSString stringWithFormat:@"%@书券",dic[@"rewardNum"]];;
    [self.bookLabel sizeToFit];
    self.bookLabel.centerX = self.coinMoneyLabel.centerX;
    self.bookLabel.centerY = self.coinMoneyLabel.centerY + 20*kUIScaleBasePlus;
    
    [self.giveImageView setX:CGRectGetMinX(self.bookLabel.frame)-9*kUIScaleBasePlus-15*kUIScaleBasePlus];
    
    if ([isFirstRecharge isEqualToString:@"0"])
    {
        self.firstRechargeImageView.hidden = YES;
    }
    else
    {
        [self.firstRechargeImageView setX:CGRectGetMaxX(self.bookLabel.frame)+13*kUIScaleBasePlus];
        self.firstRechargeImageView.hidden = NO;
    }
}

- (void)btnSelectedAndChangeState
{
    self.moneyLabel.textColor = JSAMainBgColor;
    self.bookLabel.textColor = JSAMainBgColor;
    self.giveImageView.image = [UIImage imageNamed:@"present_selected"];
    self.firstRechargeImageView.image = [UIImage imageNamed:@"first_selected"];
}

- (void)btnUnSelectedAndChangeState//没选择后的颜色
{
    self.moneyLabel.textColor = LCHexColor(0x000000);
    self.bookLabel.textColor = LCHexColor(0x000000);
    self.giveImageView.image = [UIImage imageNamed:@"present_ticket"];
    self.firstRechargeImageView.image = [UIImage imageNamed:@"first_charge"];
}
@end
